package com.tigercel.xiangchengyun.adapter

import android.support.v7.widget.RecyclerView
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import com.tigercel.xiangchengyun.R
import com.tigercel.xiangchengyun.entity.NewsBean
import kotlinx.android.synthetic.main.item_news_special.view.*


class NewsSpecialAdapter(private val news: List<NewsBean>,
                         private val itemClick: (NewsBean) ->Unit) :
        RecyclerView.Adapter<NewsSpecialAdapter.ViewHolder>() {
    override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ViewHolder? {
        val view = LayoutInflater.from(parent.context)
                .inflate(R.layout.item_news_special, parent, false)
        return ViewHolder(view ,itemClick)
    }

    override fun getItemCount(): Int = news.size

    override fun onBindViewHolder(holder: ViewHolder, position: Int) {
        holder.bindNews(news[position])

    }

    class ViewHolder(view: View, private val itemClick: (NewsBean) -> Unit) :
            RecyclerView.ViewHolder(view)
    {
        fun bindNews(newsBean: NewsBean) {
            with(newsBean) {
                itemView.image
                itemView.title.text = title
                itemView.time.text = pub_time
                itemView.tv_look_up.text = "$lookUp"
                itemView.setOnClickListener { itemClick(this) }
            }
        }

    }

}